﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace MainFrame
{
    public partial class PageManual : Form
    {
        public PageManual()
        {
            InitializeComponent();
        }
        bool isFirst = true;
        private void tabPage4_Click(object sender, EventArgs e)
        {
           
        }

        private void button10_Click(object sender, EventArgs e)
        {

        }
        public List<Button> lst_btnCut = new List<Button>();
        public List<Button> lst_btnLabel = new List<Button>();
        public List<Button> lst_btnConvery = new List<Button>();
        public string[] arr_axis;
        private List<Button> GetButtonList(GroupBox gBox)
        {
            var btnList = new List<Button>();
            foreach (var curButon in gBox.Controls)
            {
                if(curButon is Button)
                {
                    btnList.Add((Button)curButon);
                }
            }
            return btnList;
        }
        private void PageManual_Load(object sender, EventArgs e)
        {
            if(isFirst)
            {
                isFirst = false;
                ckb_plate1.Checked = true;
                lst_btnConvery =GetButtonList(gbx_Convery);
                lst_btnConvery.ForEach(a => a.Click += btn_Convery);
                lst_btnCut = GetButtonList(gbx_Cut);
                lst_btnCut.ForEach(a => a.Click += btn_Cut);
                lst_btnLabel = GetButtonList(gbx_Label);
                lst_btnLabel.ForEach(a => a.Click += btn_Label);
              
                arr_axis = Enum.GetNames(typeof(e_card1_axis));
                cbx_Axis.Items.AddRange(arr_axis);
                cbx_Axis.SelectedIndex = 0;
                Task.Factory.StartNew(Task_airInput);
                ckb_IsSaftGate.Checked = GlobalVar.closeSave.IsSaftGate;
                ckb_downPro.Checked = GlobalVar.IsRealsePro;
                ckb_IsManThrough.Checked = GlobalVar.IsManThrought;
                ckb_IsOldTest.Checked = GlobalVar.IsOldTest;
                ckb_isThrough.Checked = GlobalVar.IsThrought;
            }
        }
        private Color Color_select = Color.Orange;
        private Color Color_noselect = Color.Transparent;
        private void btn_Convery(object sender, EventArgs e)
        {
            displalyInfo.displayInfoMain(((Button)sender).Text + "按钮按下");
            var arr_step = Enum.GetNames(typeof(e_Step_ConveryUp));
            lst_btnConvery.ForEach(a => a.BackColor = Color_noselect);
            if (arr_step.Contains(((Button)sender).Text.Trim()))
            {
                ((Button)sender).BackColor = Color_select;
                var e_step = (e_Step_ConveryUp)Enum.Parse(typeof(e_Step_ConveryUp), ((Button)sender).Text);
                    GlobalMotion.Step_ConveryUp(e_step, e_MachineStatus.无控制);
            }
            else
            {
                MessageBox.Show($"请注册{((Button)sender).Text }按钮功能");
            }
        }
        private void btn_Cut(object sender, EventArgs e)
        {
            displalyInfo.displayInfoMain(((Button)sender).Text + "按钮按下");
            var arr_step = Enum.GetNames(typeof(e_Step_Cut));
            lst_btnCut.ForEach(a => a.BackColor = Color.Transparent);
            if (arr_step.Contains(((Button)sender).Text.Trim()))
            {
                ((Button)sender).BackColor = Color_select;
                var e_step = (e_Step_Cut)Enum.Parse(typeof(e_Step_Cut), ((Button)sender).Text);
                var curPlate = GetPlateSelect();
                if (curPlate == e_platePro.双平台无)
                {
                    MessageBox.Show("请选择平台");
                    return;
                }
                else
                {
                    if (e_step == e_Step_Cut.吹气除膜|| e_step == e_Step_Cut.吹气除尘)
                    {
                        Task.Run(() => GlobalMotion.Step_Cut(e_step, curPlate, e_MachineStatus.无控制));
                    }
                    else
                        GlobalMotion.Step_Cut(e_step, curPlate, e_MachineStatus.无控制);
                }
            }else
            {
                MessageBox.Show($"请注册{((Button)sender).Text }按钮功能");
            }
        }
        private void btn_Label(object sender, EventArgs e)
        {
            displalyInfo.displayInfoMain(((Button)sender).Text + "按钮按下");
            var arr_step = Enum.GetNames(typeof(e_Step_Label));
            lst_btnLabel.ForEach(a => a.BackColor = Color_noselect);
            if (arr_step.Contains(((Button)sender).Text.Trim()))
            {
                ((Button)sender).BackColor = Color_select;
                var e_step = (e_Step_Label)Enum.Parse(typeof(e_Step_Label), ((Button)sender).Text);
                var curPlate = GetPlateSelect();
                if (curPlate == e_platePro.双平台无)
                {
                    MessageBox.Show("请选择平台");
                    return;
                }
                else
                {
                    
                    GlobalMotion.Step_Labeling(e_step, curPlate, e_MachineStatus.手动界面);
                }
            }
            else
            {
                MessageBox.Show($"请注册{((Button)sender).Text }按钮功能");
            }
        }
        private e_platePro GetPlateSelect()
        {
            try
            {
                if (ckb_plate1.Checked && ckb_plate2.Checked)
                    return e_platePro.双平台有;
                else if (ckb_plate1.Checked)
                    return e_platePro.平台1;
                else if (ckb_plate2.Checked)
                    return e_platePro.平台2;
                else
                    return e_platePro.双平台无;
            }
            catch(Exception ex)
            {
                return e_platePro.双平台无;
            }
           
        }
   
        private void Task_airInput()
        {
            var Color_height = Color.Green;
            var Color_low = Color.Gray;
            while (!GlobalVar.isExit)
            {
                Thread.Sleep(40);
                this.BeginInvoke(new Action(() =>
                {
                    if(MotionControl.GlobalVariable.OperLevel == (int)MotionControl.operLevel.superAdmin)
                    {
                        gbx_Convery.Visible = true;
                        gbx_Cut.Visible = true;
                        gbx_Label.Visible = true;
                        btn_LaserStart.Visible = true;
                        btn_labelStart.Visible = true;
                    }
                    else
                    {
                        gbx_Convery.Visible = false;
                        gbx_Cut.Visible = false;
                        gbx_Label.Visible = false;
                        if (MotionControl.GlobalVariable.OperLevel == (int)MotionControl.operLevel.operatorStaff)
                        {
                            btn_LaserStart.Visible = false;
                            btn_labelStart.Visible = false;
                        } else
                        {
                            btn_LaserStart.Visible = true;
                            btn_labelStart.Visible = true;
                        }
                    }
                    nud_nfly1.Value = GlobalVar.closeSave.curFly1Count;
                    nud_nfly2.Value = GlobalVar.closeSave.curFly2Count;
                    rbt_frontAir_down.Checked = GlobalMotion.Input_CardEx2[(int)e_input_extCard2.上层阻挡气缸原点1];
                    rbt_frontAir_up.Checked = GlobalMotion.Input_CardEx1[(int)e_input_extCard1.上层阻挡气缸到位1];

                    rbt_firstAir_down2.Checked = GlobalMotion.Input_CardEx2[(int)e_input_extCard2.上层阻挡气缸原点2];
                    rbt_firstAir_up2.Checked = GlobalMotion.Input_CardEx1[(int)e_input_extCard1.上层阻挡气缸到位2];

                    rbt_secondAir_down2.Checked = GlobalMotion.Input_CardEx2[(int)e_input_extCard2.上层阻挡气缸原点3];
                    rbt_secondAir_up2.Checked = GlobalMotion.Input_CardEx1[(int)e_input_extCard1.上层阻挡气缸到位3];

                    rbt_firstAir_up1.Checked = GlobalMotion.Input_CardEx1[(int)e_input_extCard1.上层顶升气缸到位1];
                    rbt_firstAir_down1.Checked = GlobalMotion.Input_CardEx2[(int)e_input_extCard2.上层顶升气缸原点1];
                    rbt_secondAir_up1.Checked = GlobalMotion.Input_CardEx1[(int)e_input_extCard1.上层顶升气缸到位2];
                    rbt_secondAir_down1.Checked =  GlobalMotion.Input_CardEx2[(int)e_input_extCard2.上层顶升气缸原点2];
                 

                    lbl_入料阻挡伸出.ForeColor = rbt_frontAir_up.Checked ? Color_height : Color_low;
                    lbl_入料阻挡缩回.ForeColor = rbt_frontAir_down.Checked ? Color_height : Color_low;
                    lbl_一段阻挡伸出.ForeColor = rbt_firstAir_up2.Checked ? Color_height : Color_low;
                    lbl_一段阻挡缩回.ForeColor = rbt_firstAir_down2.Checked ? Color_height : Color_low;
                    lbl_二段阻挡伸出.ForeColor = rbt_secondAir_up2.Checked ? Color_height : Color_low;
                    lbl_二段阻挡缩回.ForeColor = rbt_secondAir_down2.Checked ? Color_height : Color_low;
                    lbl_一段顶升伸出.ForeColor = rbt_firstAir_up1.Checked ? Color_height : Color_low;
                    lbl_二段顶升伸出.ForeColor = rbt_secondAir_up1.Checked ? Color_height : Color_low;
                    lbl_一段顶升缩回.ForeColor = rbt_firstAir_down1.Checked ? Color_height : Color_low;
                    lbl_二段顶升缩回.ForeColor = rbt_secondAir_down1.Checked ? Color_height : Color_low;

                    rbt_cutair1.Checked = GlobalMotion.Output_CardEx1[(int)e_output_extCard1.撕膜垃圾位吹膜];
                    rbt_cutair2.Checked = GlobalMotion.Output_CardEx1[(int)e_output_extCard1.撕膜后除尘];
                    bool IsNG取料位 = false;
                    bool IsNG放料位 = false;
                    bool Is吸标NG吸真空 = false;
                    var curPlate = GetPlateSelect();
                    switch(curPlate)
                    {
                        case e_platePro.平台1:
                            rbt_cutClamp1.Checked = !GlobalMotion.Output_CardEx2[(int)e_output_extCard2.撕膜气缸1];
                            rbt_label_air11.Checked = GlobalMotion.Output_CardEx2[(int)e_output_extCard2.NG真空吸产品1];
                            rbt_label_air21.Checked = GlobalMotion.Input_CardEx2[(int)e_input_extCard2.贴标升降气缸原点1];
                            rbt_label_air22.Checked = GlobalMotion.Input_CardEx1[(int)e_input_extCard1.贴标气缸到位1];
                            rbt_label_air31.Checked = !GlobalMotion.Input_CardEx2[(int)e_input_extCard2.吸标靶面真空报警1];
                            rbt_NG_air.Checked = GlobalMotion.Input_CardEx1[(int)e_input_extCard1.平台1吸标NG抬起到位];
                            IsNG取料位 = GlobalMotion.Input_CardEx1[(int)e_input_extCard1.平台1吸标NG取料位];
                            IsNG放料位 = GlobalMotion.Input_CardEx1[(int)e_input_extCard1.平台1吸标NG放料位];
                            Is吸标NG吸真空= GlobalMotion.Output_CardEx1[(int)e_output_extCard1.NG取标吸气1];
                            break;
                        case e_platePro.平台2:
                            rbt_cutClamp1.Checked = !GlobalMotion.Output_CardEx2[(int)e_output_extCard2.撕膜气缸2];
                            rbt_label_air11.Checked = GlobalMotion.Output_CardEx2[(int)e_output_extCard2.NG真空吸产品2];
                            rbt_label_air21.Checked = GlobalMotion.Input_CardEx2[(int)e_input_extCard2.贴标升降气缸原点2];
                            rbt_label_air22.Checked = GlobalMotion.Input_CardEx1[(int)e_input_extCard1.贴标气缸到位2];
                            rbt_label_air31.Checked = !GlobalMotion.Input_CardEx2[(int)e_input_extCard2.吸标靶面真空报警2];
                            rbt_NG_air.Checked = GlobalMotion.Input_CardEx1[(int)e_input_extCard1.平台2吸标NG抬起到位];
                            IsNG取料位 = GlobalMotion.Input_CardEx1[(int)e_input_extCard1.平台2吸标NG取料位];
                            IsNG放料位 = GlobalMotion.Input_CardEx1[(int)e_input_extCard1.平台2吸标NG放料位];
                            Is吸标NG吸真空 = GlobalMotion.Output_CardEx1[(int)e_output_extCard1.NG取标吸气2];
                            break;
                        case e_platePro.双平台有:
                            rbt_cutClamp1.Checked = !GlobalMotion.Output_CardEx2[(int)e_output_extCard2.撕膜气缸1]&& !GlobalMotion.Output_CardEx2[(int)e_output_extCard2.撕膜气缸2];
                            rbt_label_air11.Checked = GlobalMotion.Output_CardEx2[(int)e_output_extCard2.NG真空吸产品1]&& GlobalMotion.Output_CardEx2[(int)e_output_extCard2.NG真空吸产品2];
                            rbt_label_air21.Checked = GlobalMotion.Input_CardEx2[(int)e_input_extCard2.贴标升降气缸原点1]&& GlobalMotion.Input_CardEx2[(int)e_input_extCard2.贴标升降气缸原点2];
                            rbt_label_air22.Checked = GlobalMotion.Input_CardEx1[(int)e_input_extCard1.贴标气缸到位1]&& GlobalMotion.Input_CardEx1[(int)e_input_extCard1.贴标气缸到位2];
                            rbt_label_air31.Checked = !GlobalMotion.Input_CardEx2[(int)e_input_extCard2.吸标靶面真空报警1]&&!GlobalMotion.Input_CardEx2[(int)e_input_extCard2.吸标靶面真空报警2];
                            rbt_NG_air.Checked = GlobalMotion.Input_CardEx1[(int)e_input_extCard1.平台1吸标NG抬起到位]&&GlobalMotion.Input_CardEx1[(int)e_input_extCard1.平台2吸标NG抬起到位];
                            IsNG取料位 = GlobalMotion.Input_CardEx1[(int)e_input_extCard1.平台1吸标NG取料位]&&GlobalMotion.Input_CardEx1[(int)e_input_extCard1.平台2吸标NG取料位];
                            IsNG放料位 = GlobalMotion.Input_CardEx1[(int)e_input_extCard1.平台1吸标NG放料位]&& GlobalMotion.Input_CardEx1[(int)e_input_extCard1.平台2吸标NG放料位];
                            Is吸标NG吸真空 = GlobalMotion.Output_CardEx1[(int)e_output_extCard1.NG取标吸气1]&&GlobalMotion.Output_CardEx1[(int)e_output_extCard1.NG取标吸气2];
                            break;
                    }
                    lbl_NG取工装吸气.ForeColor = rbt_label_air11.Checked ? Color_height : Color_low;
                    lbl_NG取工装破气.ForeColor = !rbt_label_air11.Checked ? Color_height : Color_low;
                    lbl_取标气缸伸出.ForeColor = rbt_label_air22.Checked ? Color_height : Color_low;
                    lbl_取标气缸缩回.ForeColor = rbt_label_air21.Checked ? Color_height : Color_low;
                    lbl_取标靶面吸气.ForeColor = rbt_label_air31.Checked ? Color_height : Color_low;
                    lbl_取标靶面破气.ForeColor = !rbt_label_air31.Checked ? Color_height : Color_low;
                    lbl_吸标NG气缸伸出.ForeColor = rbt_NG_air.Checked ? Color_height : Color_low;
                    lbl_吸标NG气缸缩回.ForeColor = !rbt_NG_air.Checked ? Color_height : Color_low;
                    lbl_夹住膜.ForeColor= rbt_cutClamp1.Checked ? Color_height : Color_low;
                    lbl_松开膜.ForeColor = !rbt_cutClamp1.Checked ? Color_height : Color_low;
                    lbl_NG旋转到放料.ForeColor = IsNG放料位 ? Color_height : Color_low;
                    lbl_NG旋转到取料.ForeColor = IsNG取料位 ? Color_height : Color_low;
                    lbl_吸标NG真空吸气.ForeColor = Is吸标NG吸真空 ? Color_height : Color_low;
                    lbl_吸标NG真空破气.ForeColor = !Is吸标NG吸真空 ? Color_height : Color_low;
                    var axisIndex = getCurAxis();
                    if (axisIndex >= 0&& GlobalMotion.Card_1!=null)
                    {
                        var curPos=GlobalMotion.Card_1.AxisList[axisIndex].m_AxisSts.CurrPosi;
                        var curVel = GlobalMotion.Card_1.AxisList[axisIndex].m_movePrm.RunVel;
                        lbl_curPos.Text = curPos.ToString("F03");
                        lbl_curVel.Text = curVel.ToString();
                    }
                    
                }));
            }
        }

        private void button18_Click(object sender, EventArgs e)
        {

        }

        private void btn_ConveyDown_maual_Click(object sender, EventArgs e)
        {
            displalyInfo.displayInfoMain(((Button)sender).Text + "按钮按下");
            GlobalMotion.ConveryControrl(e_ConveryControl.下层输送停止);
        }

        private void btn_ConveyDown_Click(object sender, EventArgs e)
        {
            displalyInfo.displayInfoMain(((Button)sender).Text + "按钮按下");
            GlobalMotion.ConveryControrl(e_ConveryControl.下层输送启动);
        }

        private void btn_Convey_Click(object sender, EventArgs e)
        {
            displalyInfo.displayInfoMain(((Button)sender).Text + "按钮按下");
            GlobalMotion.ConveryControrl(e_ConveryControl.上层输送启动);
        }

        private void btn_ConveyStop_Click(object sender, EventArgs e)
        {
            displalyInfo.displayInfoMain(((Button)sender).Text + "按钮按下");
            GlobalMotion.ConveryControrl(e_ConveryControl.上层输送停止);
        }
        public int getCurAxis()
        {
            var res = -1;
            if (arr_axis != null && arr_axis.Length > 0)
            {
                var axisName = cbx_Axis.Text;
                if(!string.IsNullOrEmpty(axisName))
                    if(arr_axis.Contains(axisName))
                    {
                        return arr_axis.ToList().IndexOf(axisName);
                    }
             }
            return -1;
        }
        private void btn_negtive_Click(object sender, EventArgs e)
        {
            var axisIndex = getCurAxis();
            if (axisIndex >= 0)
                GlobalMotion.Card_1.AxisList[axisIndex].PointMove((double)-nud_smallPos.Value, false);
        }

        private void btn_postive_Click(object sender, EventArgs e)
        {
            var axisIndex = getCurAxis();
            if (axisIndex >= 0)
                GlobalMotion.Card_1.AxisList[axisIndex].PointMove((double)nud_smallPos.Value, false);
        }

        private void btn_moveToPos_Click(object sender, EventArgs e)
        {
            var axisIndex = getCurAxis();
            if (axisIndex >= 0)
                GlobalMotion.Card_1.AxisList[axisIndex].PointMove((double)nud_pos.Value, true);
        }

        private void button46_Click(object sender, EventArgs e)
        {

        }

        private void button5_Click(object sender, EventArgs e)
        {

        }

        private void btn_flystart1_Click(object sender, EventArgs e)
        {
            GlobalVar.IsflyStart1 = true;
        }
        private void btn_flystart2_Click(object sender, EventArgs e)
        {
            GlobalVar.IsflyStart2 = true;
        }

        private void btn_fly1Clear_Click(object sender, EventArgs e)
        {
            GlobalVar.closeSave.curFly1Count = 0;

        }

        private void btn_fly2Clear_Click(object sender, EventArgs e)
        {
            GlobalVar.closeSave.curFly2Count = 0;

        }
        private void btn_ResetCut_Click(object sender, EventArgs e)
        {
            if (!GlobalMotion.Input_CardEx2[(int)e_input_extCard2.上输送治具检测2] && GlobalVar.isAutoRun)
            {
                var msg = "撕膜工位无治具,操作无效";
                MessageBox.Show(msg);
                return;
            }
            GlobalMotion.Step_ConveryUp(e_Step_ConveryUp.一段治具升起);
            if (GlobalVar.Laser_pros == null || GlobalVar.Laser_pros.Count == 0)
            {
                GlobalVar.Laser_pros = new List<ProductInfo>();
                GlobalVar.Laser_pros.Add(new ProductInfo()
                {
                    LaserTime = DateTime.Now,
                    typeName = GlobalVar.closeSave.CurrentTypeName,
                    ProId = "",
                    ProNo = 1,
                    IsProcessAlarm = 1,
                    Result_up = e_Result.进料OK.ToString()
                });
                GlobalVar.Laser_pros.Add(new ProductInfo()
                {
                    LaserTime = DateTime.Now,
                    typeName = GlobalVar.closeSave.CurrentTypeName,
                    ProId = "",
                    ProNo = 2,
                    IsProcessAlarm = 1,
                    Result_up = e_Result.进料OK.ToString()
                });
            }
            GlobalMotion.e_ConveryLaser = e_Flow_ConveryUp.一段治具到位;
        }

        private void btn_CutOver_Click(object sender, EventArgs e)
        {
            if (!GlobalMotion.Input_CardEx2[(int)e_input_extCard2.上输送治具检测2] && GlobalVar.isAutoRun)
            {
                var msg = "撕膜工位无治具,操作无效";
                MessageBox.Show(msg);
                return;
            }
            GlobalMotion.Step_ConveryUp(e_Step_ConveryUp.一段治具升起);
            if (GlobalVar.Laser_pros == null || GlobalVar.Laser_pros.Count == 0)
            {
                GlobalVar.Laser_pros = new List<ProductInfo>();
              
                bool IshavePro1 = !GlobalMotion.Input_CardEx2[(int)e_input_extCard2.上输送产品检测1];
                bool IshavePro2 = !GlobalMotion.Input_CardEx2[(int)e_input_extCard2.上输送产品检测2];
                GlobalVar.Laser_pros.Add(new ProductInfo()
                {
                    LaserTime = DateTime.Now,
                    typeName = GlobalVar.closeSave.CurrentTypeName,
                    ProId = "",
                    ProNo = 1,
                    IsProcessAlarm = 1,
                    Result_up = IshavePro1 ? e_Result.进料OK.ToString() : e_Result.进料读卡NG.ToString(),
                    Result_Cut = IshavePro1 ? e_Result.撕膜OK.ToString() : e_Result.撕膜NG.ToString(),
                });
                GlobalVar.Laser_pros.Add(new ProductInfo()
                {
                    LaserTime = DateTime.Now,
                    typeName = GlobalVar.closeSave.CurrentTypeName,
                    ProId = "",
                    ProNo = 2,
                    IsProcessAlarm = 1,
                    Result_up = IshavePro2 ? e_Result.进料OK.ToString() : e_Result.进料读卡NG.ToString(),
                    Result_Cut = IshavePro2 ? e_Result.撕膜OK.ToString() : e_Result.撕膜NG.ToString(),
                });
            }
            GlobalMotion.e_ConveryLaser = e_Flow_ConveryUp.一段治具加工完成;
        }

        private void btn_resetLabel_Click(object sender, EventArgs e)
        {
            if (!GlobalMotion.Input_CardEx2[(int)e_input_extCard2.上输送治具检测3] && GlobalVar.isAutoRun)
            {
                var msg = "贴标工位无治具,操作无效";
                MessageBox.Show(msg);
                return;
            }
            GlobalMotion.Step_ConveryUp(e_Step_ConveryUp.二段治具升起);
            if (GlobalVar.Label_pros == null || GlobalVar.Label_pros.Count == 0)
            {
                GlobalVar.Label_pros = new List<ProductInfo>();
                GlobalVar.Label_pros.Add(new ProductInfo()
                {
                    LaserTime = DateTime.Now,
                    typeName = GlobalVar.closeSave.CurrentTypeName,
                    ProId = "",
                    ProNo = 1,
                    IsProcessAlarm = 1,
                    Result_up = e_Result.进料OK.ToString(),

                });
                GlobalVar.Label_pros.Add(new ProductInfo()
                {
                    LaserTime = DateTime.Now,
                    typeName = GlobalVar.closeSave.CurrentTypeName,
                    ProId = "",
                    ProNo = 2,
                    IsProcessAlarm = 1,
                    Result_up = e_Result.进料OK.ToString()
                });
            }
            GlobalMotion.e_ConveryLabel = e_Flow_ConveryUp.二段治具到位;
        }

        private void btn_LabelOver_Click(object sender, EventArgs e)
        {
            if (!GlobalMotion.Input_CardEx2[(int)e_input_extCard2.上输送治具检测3] && GlobalVar.isAutoRun)
            {
                var msg = "贴标工位无治具,操作无效";
                MessageBox.Show(msg);
                return;
            }
            GlobalMotion.Step_ConveryUp(e_Step_ConveryUp.二段治具升起);
            if (GlobalVar.Label_pros == null || GlobalVar.Label_pros.Count == 0)
            {
                GlobalVar.Label_pros = new List<ProductInfo>();
            
                bool IshavePro3 = !GlobalMotion.Input_CardEx2[(int)e_input_extCard2.上输送产品检测3];
                bool IshavePro4 = !GlobalMotion.Input_CardEx2[(int)e_input_extCard2.上输送产品检测4];
                GlobalVar.Label_pros.Add(new ProductInfo()
                {
                    LaserTime = DateTime.Now,
                    typeName = GlobalVar.closeSave.CurrentTypeName,
                    ProId = "",
                    ProNo = 1,
                    IsProcessAlarm = 1,

                    Result_up = e_Result.进料OK.ToString(),
                    Result_Label = IshavePro3 ? e_Result.贴膜OK.ToString() : e_Result.贴膜NG.ToString(),
                    Result_down = IshavePro3 ? e_Result.出料OK.ToString() : e_Result.出料NG.ToString(),
                });
                GlobalVar.Label_pros.Add(new ProductInfo()
                {
                    LaserTime = DateTime.Now,
                    typeName = GlobalVar.closeSave.CurrentTypeName,
                    ProId = "",
                    ProNo = 2,
                    IsProcessAlarm = 1,
                    Result_up = e_Result.进料OK.ToString(),
                    Result_Label = IshavePro4 ? e_Result.贴膜OK.ToString() : e_Result.贴膜NG.ToString(),
                    Result_down = IshavePro4 ? e_Result.出料OK.ToString() : e_Result.出料NG.ToString(),
                });
            }

            GlobalMotion.e_ConveryLabel = e_Flow_ConveryUp.二段治具加工完成;
        }

        private void btn_LaserStart_Click(object sender, EventArgs e)
        {
            GlobalVar.Cut_Start = true;
        }

        private void btn_labelStart_Click(object sender, EventArgs e)
        {
            GlobalVar.Label_Start = true;
        }

        private void tabPage1_Click(object sender, EventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {

        }

        private void button25_Click(object sender, EventArgs e)
        {

        }

        private void button14_Click(object sender, EventArgs e)
        {

        }

        private void button19_Click(object sender, EventArgs e)
        {

        }

        private void button21_Click(object sender, EventArgs e)
        {

        }

        private void btn_airdown_Click(object sender, EventArgs e)
        {
            displalyInfo.displayInfoMain(((Button)sender).Text + "按钮按下");
            var arr_Manual_Air = Enum.GetNames(typeof(e_Manual_Air));
            var arr_convery = Enum.GetNames(typeof(e_Step_ConveryUp));
            var str_step = "";
            try
            {
                if (((Button)sender).Tag != null)
                {
                    str_step = ((Button)sender).Tag.ToString().Trim();
                }
            }
            catch
            {

            }
            if (!string.IsNullOrEmpty(str_step))
            {
                if (arr_Manual_Air.Contains(str_step))
                {
                    var e_step = (e_Manual_Air)Enum.Parse(typeof(e_Manual_Air), str_step);
                    var curPlate = GetPlateSelect();
                    if (curPlate == e_platePro.双平台无 && !arr_convery.Contains(str_step))
                    {
                        MessageBox.Show("请选择平台");
                        return;
                    }
                    else
                    {
                        GlobalMotion.Step_Manual_Air(e_step, curPlate);
                    }
                }
                else if(str_step== "吸标NG旋转到取标位"|| str_step=="吸标NG旋转到放标位")
                {
                    var e_step = (e_Step_Label)Enum.Parse(typeof(e_Step_Label), str_step);
                    var curPlate = GetPlateSelect();
                    if (curPlate == e_platePro.双平台无 && !arr_convery.Contains(str_step))
                    {
                        MessageBox.Show("请选择平台");
                        return;
                    }
                    else
                    {
                        GlobalMotion.Step_Labeling(e_step, curPlate,e_MachineStatus.无控制);
                    }
                }
                else
                {
                    MessageBox.Show($"请联系开发人员注册{((Button)sender).Text }按钮功能");
                    return;
                }
            }
            else
            {
                MessageBox.Show($"请联系开发人员注册{((Button)sender).Text }按钮功能");
            }
        }

       

        private async void btn_connect_Click(object sender, EventArgs e)
        {
            btn_connect.Enabled = false;

            await Task.Run(() =>
            {
                GlobalVar.isExit = true;
                Thread.Sleep(1000);
                var res = GlobalMotion.Card_1.SoftReset((ushort)GlobalMotion.Card_1.m_CardID);
                if (res != -1)
                {
                    MessageBox.Show("已能正常连接运动控制卡,请重启软件生效");
                }
            });
            btn_connect.Enabled = true;
        }

        private void btn_ManSignal_Click(object sender, EventArgs e)
        {
            GlobalVar.IsManFinishSignal = true;
        }

        private void Ckb_IsSaftGate_CheckedChanged(object sender, EventArgs e)
        {
            GlobalVar.closeSave.IsSaftGate = ckb_IsSaftGate.Checked;
            
        }

        private void ckb_IsOldTest_CheckedChanged(object sender, EventArgs e)
        {
            GlobalVar.IsOldTest = ckb_IsOldTest.Checked;
        }

        private void ckb_isThrough_CheckedChanged(object sender, EventArgs e)
        {
            GlobalVar.IsThrought = ckb_isThrough.Checked;
        }
        private void ckb_downPro_CheckedChanged(object sender, EventArgs e)
        {
            GlobalVar.IsRealsePro = ckb_downPro.Checked;
        }

        private void ckb_IsManThrough_CheckedChanged(object sender, EventArgs e)
        {
            GlobalVar.IsManThrought = ckb_IsManThrough.Checked;
        }

        private void tabPage2_Click(object sender, EventArgs e)
        {

        }

        private void button6_Click(object sender, EventArgs e)
        {

        }

        private void button47_Click(object sender, EventArgs e)
        {

        }

        private void button45_Click(object sender, EventArgs e)
        {

        }

        private void ckb_plate1_CheckedChanged(object sender, EventArgs e)
        {
            if (ckb_plate1.Checked)
            {
                ckb_plate2.Checked = false;
            }
        }

        private void ckb_plate2_CheckedChanged(object sender, EventArgs e)
        {
            if (ckb_plate2.Checked)
            {
                ckb_plate1.Checked = false;
            }
        }
    }
}
